A man has appeared in court accused of masturbating in public.