Edit number of objects in NvDsFrameMeta.

I am trying to write a custom plugin based on the given gstdsexample. What I can’t wrap my head around is, how do I edit the number of objects inside NvDsFrameMeta.
One way I figured would be to free the previous meta and attach new meta with the desired number of objects, but that would mean discarding all the previous information.
bbparams = (NvDsFrameMeta *) dsmeta->meta_data;
I need to modify these two fields;
for the sake of simplicity assume num_rects is currently 2, I want to change it to 1 or 3 objects.