Fixed modulus related bug in cost matrix generation. EMD works now.