Fix bug due to wrong loop variables

The iterative refinement algorithm in the paper is correct but
in the implementation I accidentally swapped the loop variables.