How can I correctly setup attachInterrupt() in this sketch?

You take a local copy of the volatile variables in the critical section in the loop function.
That is all that needs to be in the critical section, and then you work on the copies in loop().