Don't modify temporary variables in your NMI.
Just don't.
Failure to observe this rule can lead to many, many wasted hours trying to track down a really, really tricky bug.
I tend to have seperate variables for NMI and the main program for this reason.
I have separate variables for the NMI and IRQ most of the time too. In the NMI I only change variables that are otherwise controlled by the main thread when the game frame was flagged as complete, meaning that the main thread is doing nothing but waiting for the NMI, and it expects the variables to be changed.
Very good, but I'd like to propose an addendum: if you absolutely must use the temp variables in an NMI, push them to the stack first, remembering to pull them in reverse order afterwards.
I absolutely agree with this golden rule! I have temp variables separate for my main and NMI loops. I don't usually do anything with IRQs, so I don't have temp variables for that. My math routines are all designed to work with Main's temp vars, so if I have to use those in the NMI routine (which I shouldn't, because all calculations should really be done in Main), I just load the temp vars and push them to the stack.