limit the search area for a matching pair

I have a 500k org file that I keep notes in, and if I try to insert a parenthesis near the beginning, autopair will freeze emacs for about 10 seconds while it looks for a matching paren in the rest of the document. So here is a new variable and condition that will limit the search space. It seems to work and doesn't break backward or forward search, at least as far as I can tell from a day of working with the patched version.