The first one is the traffic light detection that locates the spatial coordinates of the centers of the lights.
In practice this detection requires multiple frames as the different colored lights appear at different time.
Once the coordinates of the lights are calculated the set of lights with the largest dimension is chosen from which the light sequence is constructed in the second subfunction.