MAINT: reduce scope of some variables in indexing code

also improves code generation with gcc-4.8 leading up to a 10%
performance increase on some cpus by removing a stack spill.
Merge pull request #4772 from juliantaylor/scope-red

MAINT: reduce scope of some variables in indexing code