To avoid future embarrassment, you can establish some unspoken rules for yourself. If you know your neighbor's wife has certain routines, like taking care of the garden at a specific time, you can adjust your own schedule. Additionally, when you are in areas where there might be a chance of seeing something you shouldn't, keep your eyes in a more appropriate direction. And if you have to interact with your neighbors, keep the conversation light and not related to this incident at all.
One way is to be more careful about your own movements. For example, if there's a chance of such an encounter in the yard or common areas, be more aware of your surroundings. Also, communicate less obtrusively with your neighbors so that you don't accidentally end up in an awkward situation again.
Firstly, you can make sure to respect the privacy of your neighbor's property. For instance, don't go near their windows or areas that might be considered private. Secondly, improve communication with your neighbor in a proper way. Let him know that you respect their family and privacy. This can help in creating a more comfortable environment for both sides. Also, you can focus more on your own personal space and activities, reducing the chances of being in an inappropriate situation.