You didnt have to show them your bag. Even if they were cops you didnt even have to talk to them unless they were placing you under arrest. They couldnt do that unless they had legitimate reason to suspect that you had broken a law. You can just ask if you are free to go and they have to let you go.
But then I am white, so the rules only apply to me. I probably would be scared shitless of not complying to police if I were black. I would be terrified for my life.