recursive matching braces to a limited depth