Can topography be used to control bacteria accumulation? We address this question in the model system of smooth-swimming and run-and-tumble Escherichia coli swimming near a sinusoidal surface, and show that the accumulation of bacteria is determined by the characteristic curvature of the surface. For low curvatures, cells swim along the surface due to steric alignment and are ejected from the surface when they reach the peak of the sinusoid. Increasing curvature enhances this effect and reduces the density of bacteria in the curved surface. However, for curvatures larger than κ^{*}≈0.25µm^{-1}, bacteria become trapped in the valleys, where they can remain for long periods of time. Minimal simulations considering only steric interactions with the surface reproduce these results and give insights into the physical mechanisms defining the critical curvature, which is found to scale with the inverse of the bacterial length. We show that for curvatures larger than κ^{*}, the otherwise stable alignment with the wall becomes unstable while the stable orientation is now perpendicular to the wall, thus predicting accurately the onset of trapping at the valleys.