I have just had this issue and resolved it for myself by doing the following.....
1. I made sure that my iMac & iPhone had the same amount of contacts in the all contacts.
2. I checked that both devices had the icloud settings configured correctly.
3. I turned off syncing contacts on my iPhone, and selected the remove from my phone option.
4. I turned syncing back on and again was happy that all contacts were still there.
[ The groups showing wrong contacts bug was still there ]
5. I created a new group with a new name on my iMac.
6. Selected all contacts of a bugged group and dragged them into the new group.
7. I confirmed that the new group and members had moved to the iPhone.
8. I deleted the old group on my iMac.
9. I confirmed that the old group disapeared from my iPhone.
[ Repeat steps 5-9 for any bugged group ]