Declare temp vars in the closest function scope

Allow spread temp vars to be reused in the same function scope.