It does matter how close they are, but it's a pretty wide margin and that setup looks fine. Usually you should look for 4+ teeth of engagement on the smaller sprocket for wear characteristics, and at least 90 degrees of wrap to make it unlikely to slip.