unsigned long int and long int are sort of alien integer types in OpenCV. We try to avoid them as much as possible. Consider using int for both id and rank.