Most likley bordem is why tou were stopped, but your funny remark might have reminded him of how boring he is and maybe thats why he gave you some.
You can go to court and defend yourself but expect anything, if you do make sure you have a good well constructed argument about the incident and make sure to point out relevant facts, maybe take a few pictures of the area at around the same time you were stopped to display the volume of pedestrians etc and state that the police man stopped infront of you.
Remember that the Police are allowed to stop almost anywhere and you might be reminded of this fact in court, your defence would be something like they can stop anywhere when conducting police work, although they were, it was not exactly an emergency and they placed the public at a greater risk then you did and you done in unintentionally and they clearly new where they stopped etc etc blah blah
You can go to court and defend yourself but expect anything, if you do make sure you have a good well constructed argument about the incident and make sure to point out relevant facts, maybe take a few pictures of the area at around the same time you were stopped to display the volume of pedestrians etc and state that the police man stopped infront of you.
Remember that the Police are allowed to stop almost anywhere and you might be reminded of this fact in court, your defence would be something like they can stop anywhere when conducting police work, although they were, it was not exactly an emergency and they placed the public at a greater risk then you did and you done in unintentionally and they clearly new where they stopped etc etc blah blah