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.