The variables i and j have been declared before in the same function. I changed the names to mi and mj to keep things clear.