Mask bits of reference indexes properly to avoid negative numbers entangling