Study of behavior changes in model animals is an important part of biologists' research. This requires tracking of each individual in a group of animals moving in an arena. But, manually performing tracking analysis is a laborious work. Though, machine vision is a useful tool for locomotion analysis since it can provide more precise and time efficient measurements. For analysis of a group of Drosophila (common fruit fly) using machine vision, problem of identity swapping occurs in tracking process due to abrupt behavior of flies. The main causes of identity swapping are crossing over and touching of the flies, which lead to tracking failures. This study introduces an approach to tackle identity swapping in a crossover scenario. It determines the heading direction by wing detection process, in addition to the detection of each fly's position. Using both position and heading direction information together with a combination of two assignment methods, Closest Neighbor (CN) and Predict-Matching (PM), the problem of crossover identity swapping could be considerably eliminated. The experiment's results prove that the method using both CN and PM has significant improvement over the one using only PM, which is a commonly utilized method in machine vision for locomotion analysis.