9.2.3.2 Controlling Variable Scope

There is no way to make a variable local to a { … } block in
awk, but you can make a variable local to a function. It is
good practice to do so whenever a variable is needed only in that
function.

To make a variable local to a function, simply declare the variable as
an argument after the actual function arguments
(see section Function Definition Syntax).
Look at the following example where variable
i is a global variable used by both functions foo() and
bar():