Replace loop variables (i,j) by (row_index,column_index) when relevant