rendering mask image but many parts failed to render
The object index is a property that is unique to each object, you need to have every object set to the same index if you want them to show up in the same mask.

You can do this easily by selecting all of the cars, then right clicking on the object index and choosing Copy To Selected.



Another way is to use the same material on each car and use the material index instead of object index.

As you are duplicating the cars using python, you can set the pass_index as you create each car.

def createCarWithName(self,name):
    obj = bpy.data.objects[name]
    mesh = obj.data
    new_obj = bpy.data.objects.new(name, mesh)
    bpy.context.scene.objects.link(new_obj)
    new_obj.rotation_mode = 'XYZ'# Force the right rotation mode
    new_obj.pass_index = 1