Remove shadow declaration warnings for "index" variables

Use more specific variable names for each "index".
Merge pull request #602